const { SERVER_ERR } = require("../config/error.js");

class Controller {
  async upload(ctx, next) {
    try {
      console.log(" ctx.request.file", ctx.request.file);
      const { fieldname, originalname, encoding, mimetype, destination, filename, path, size } = ctx.request.file;
      ctx.body = {
        code: 200,
        message: "上传成功",
        data: {
          fieldname,
          originalname,
          encoding,
          mimetype,
          destination,
          filename,
          path,
          size,
          url: path.replaceAll("\\", "/").replace("static", ""),
        },
      };
    } catch (error) {
      ctx.error = error;
      ctx.app.emit("error", SERVER_ERR, ctx);
    }
  }
}

module.exports = new Controller();
